<template>
<div>
  <h3>{{msg}} <span v-show="admin.username">当前用户：{{admin.username}}</span></h3>
  <router-link v-show="!admin.username" :to="{name:'login'}">点击登录</router-link>
  <a v-show="admin.username" href="javascript:void(0)" @click="logout">安全退出</a><hr/>

  <router-link :to="{name:'welcome'}">首页</router-link>
  <router-link :to="{name:'stu'}">学生管理</router-link>
  <router-link :to="{name:'acc'}">账户管理</router-link>
  <router-link :to="{name:'cate'}">类型管理</router-link>
  <router-link :to="{name:'dept'}">部门管理</router-link>
</div>
</template>

<script>
export default {
  name: "top",
  data(){
    return{
      msg:"欢迎来到我的主页",
      admin:{}
    };
  },
  methods:{
    logout(){
      //从本地获取token
      let token = localStorage.getItem("token");
      //发异步删除登录用户
      instance.get("/admin/logout?token="+token)
      .then(res => {
        localStorage.removeItem("token");
        this.admin = {};
        this.$router.push({name:"login"});
      });
    },
  },
  created() {
    let token = localStorage.getItem("token");
    instance.get("/admin/getUserInfo?token="+token)
    .then(res => {
      this.admin = res.data;
    })
  }
}
</script>

<style scoped>

</style>
